<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1">
    <!-- Google Chrome Frame也可以让IE用上Chrome的引擎: -->
    <meta name="renderer" content="webkit">
    <!--国产浏览器高速模式-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>作业管理系统</title>

    <!-- 公共样式 开始 -->
    <link rel="stylesheet" type="text/css" href="../../layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="../../css/base.css">
    <script type="text/javascript" src="../../framework/jquery-1.11.3.min.js"></script>
   + <script type="text/javascript" src="../../layui/layui.js"></script>
    <script type="text/javascript" src="../../framework/frameAll.js"></script>

    <script type="text/javascript">
        function getInfo() {
            var data = {
                title: $("input[name=title]").val(),
                describe: $("input[name=describe]").val(),
                endDate: $("input[name=endDate]").val(),
                fileName: $("input[name=fileName]").val(),
                url: $("input[name=url]").val(),
                type: $("input[name=type]").val(),
            };
            return data;
        }

        function load(data) {
            layui.use('form', function () {
                var form = layui.form;
                form.val('infoForm', {
                    title: data.title,
                    describe: data.describe,
                    endDate: data.endDate,
                    url: data.url,
                    type: data.type,
                });
            });
        }
    </script>
</head>

<body>
<div class="cBody">
    <br/>
    <form id="addForm" class="layui-form" lay-filter="infoForm">
        <div class="layui-form-item">
            <label class="layui-form-label">标题：</label>
            <div class="layui-input-inline shortInput">
                <input type="text" name="title" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述：</label>
            <div class="layui-input-inline shortInput">
                <input type="text" name="describe" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">截止时间：</label>
            <div class="layui-input-inline shortInput">
                <input type="text" name="endDate" id="date" readOnly="true" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">文件上传：</label>
            <div class="layui-input-inline shortInput">
                <button type="button" name="url"class="layui-btn" id="test">选择文件</button>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">文件名：</label>
            <div class="layui-input-inline shortInput">
                <input type="text" name="fileName" readOnly="true" autocomplete="off" class="layui-input"
                       style="border-style:none">
                <input type="hidden" name="type">
                <input type="hidden" name="url">
            </div>
        </div>

    </form>

</div>

<script>
    layui.use(['upload', 'laydate', 'element'], function () {
        var upload = layui.upload,
            laydate = layui.laydate,
            element = layui.element;
        //指定允许上传的文件类型
        upload.render({
            elem: '#test',
            url: '/HwServlet.do?action=uploadFile', //改成您自己的上传接口
            accept: 'file',
            progress: function (n, elem) {
                var percent = n + '%';
                element.progress('demo', percent); //可配合 layui 进度条元素使用
            },
            done: function (uploadData) {
                layer.msg(uploadData.msg);
                if ($("input[name=title]").val()==='') {
                    $("input[name=title]").val(uploadData.data.fileName)
                }
                $("input[name=fileName]").val(uploadData.data.fileName);
                $("input[name=url]").val(uploadData.data.url);
                $("input[name=type]").val(uploadData.data.type);
            },
        });
        //时间选择器
        var endDate = new Date(new Date().toLocaleDateString());
        // endDate = new Date(endDate.setDate(endDate.getDate() + (8 - endDate.getDay())));

        laydate.render({
            elem: '#date',
            type: 'datetime',
            // theme: 'grid',
            min: 0,
            max: 90,
            value: endDate,
            format: 'yyyy-MM-dd HH:mm:ss',
            trigger: 'click',
            btns: ['clear', 'confirm'],
        });
    });
</script>
</body>

</html>
